/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 *
 * @author Ahmed
 */
public class Conexion {
    protected Connection conn;
    
    public Conexion(){
        this.conn = null;
    }
    
    public void commit() throws SQLException{
        conn.commit();
    }
    
    public void rollback() throws SQLException{
        conn.rollback();
    }   
    
    public Connection abrirConexion() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException{
        conn = null;
        String username = "inf2260981g3dba";
        String password = "membership";
        
        String database= "inf2260981g3";
        
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        
        conn = DriverManager.getConnection("jdbc:mysql://quilla.lab.inf.pucp.edu.pe:3306/"+database, username, password);
        //conn = DriverManager.getConnection ("jdbc:mysql://localhost/inf2260981g3","root", "");
        
        conn.setAutoCommit(false);
        
//        String username = "root";
//        String password = "";
//        
//        String database = "inf2260981g3";
//        
//        Class.forName("com.mysql.jdbc.Driver").newInstance();
//        
//        conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/"+database, username, password);
//        
//        conn.setAutoCommit(false);
//        String username = "pardoyel_dp1";
//        String password = "davila";
//        
//        String database= "pardoyel_dp1";
//        
//        Class.forName("com.mysql.jdbc.Driver").newInstance();
//        
//        conn = DriverManager.getConnection("jdbc:mysql://50.87.33.40:3306/"+database, username, password);
//        
//        conn.setAutoCommit(false);
//        
        return conn;
        
    }
    
    public void setAutoCommit(boolean flag) throws SQLException{
        conn.setAutoCommit(flag);
    }
    
    public void cerrarConexion() throws SQLException{
        conn.close();
    }
    
}
